<?php

include_once "src/controller/dbmanagement/EventDBManagement.php";


/**
 * It includes all the functions for the management of the event
 *
 * @author: Amanda Dunagin
 */
class EventManagement
{
  /**
   *Precondition:  Accepts an event object: The following attributes MUST be set:
   *                - Event_Id
   *Postcondition: Find and return a specific event in the tEvents table
   *               otherwise return false
   **/
    public static function getEventByID($eventId)
    {
        try
        {
            return EventDBManagement::findEvent($eventId);
        } 
        catch (DBException $e)
        {
            throw $e;
        } 
        catch (DBConnectionException $e)
        {
            throw $e;
        }
    }

  /**
   *Precondition:  None
   *Postcondition: Find all events in the tEvents table
   *               An Array of Event objects is returned
   **/
    public static function getAllEvents()
    {
        try
        {
            return EventDBManagement::findAllEvents();
        }
        catch (DBException $e)
        {
            throw $e;
        }
        catch (DBConnectionException $e)
        {
            throw $e;
        }
    }

  /**
   *Precondition:  Accepts an userId integer: The userId MUST
   * be valid.
   *Postcondition: Find all events in the tEvents table by a userID
   *               An Array of Event objects is returned
   **/
    public static function getAllEventsByUserId($userId)
    {
        try
        {
            return EventDBManagement::findAllEvents($userId);
        }
        catch (DBException $e)
        {
            throw $e;
        }
        catch (DBConnectionException $e)
        {
            throw $e;
        }
    }

  /**
   *Precondition:  Accepts an event object: The following attributes MUST be set:
   *                - Event_Id
   *Postcondition: Removes an event from the tEvent table and returns
   *               true if successful and false otherwise.
   **/
    public static function removeEvent($eventId)
    {
        try
        {
            return EventDBManagement::deleteEventByID($eventId);
        }
        catch (DBException $e)
        {
            throw $e;
        } 
        catch (DBConnectionException $e)
        {
            throw $e;
        }
    }

  /**
   *Precondition:  Accepts an event object: The following attributes MUST be set:
   *               - UserID and
   *               - ResourceID
   *Postcondition: Adds a record into the tEvents table and returns
   *               true if successful and false otherwise.
   **/
    public static function addEvent($event)
    {
        try
        {
            return EventDBManagement::insertEvent($event);
        } 
        catch (DBException $e)
        {
            throw $e;
        } 
        catch (DBConnectionException $e)
        {
            throw $e;
        }
    }

      /**
       *Precondition:  Accepts an Event object: The following attributes MUST be set:
       *                - User_id
       *Postcondition: updates record in the tEvents table by Event_Id
       *               No Value is returned.
       **/
    public static function updateEvent($event)
    {
        try
        {
            EventDBManagement::updateEvent($event);
        } 
        catch (DBException $e)
        {
            throw $e;
        } 
        catch (DBConnectionException $e)
        {
            throw $e;
        }
    }
}
?>
